import numpy as np

import config.folder_and_file_names as fname
from discretization.get_discretization import DisData
from primarkov.build_markov_model import ModelBuilder
from generator.state_trajectory_generation import StateGeneration
from generator.to_real_translator import RealLocationTranslator
# from tools.object_store import ObjectStore
from pritree.tree_model import TreeModel
from config.parameter_carrier import ParameterCarrier
from config.parameter_setter import ParSetter
from tools.Query import SquareQuery
from tools.data_writer import DataWriter
from data_preparation.data_preparer import DataPreparer
import datetime
import os

from tools.experiment import Test

if __name__ == "__main__":
    # 获取当前进程的 ID
    pid = os.getpid()
    print(f"Current process ID: {pid}")
    writer = DataWriter()
    print('begin all1')
    print(datetime.datetime.now())
    par = ParSetter().set_up_args()
    pc = ParameterCarrier(par)
    data_preparer = DataPreparer(par)
    point_trajectory_set = data_preparer.get_trajectory_set()
    disdata1 = DisData(pc)
    grid = disdata1.get_discrete_data(point_trajectory_set)
    tm = TreeModel(pc)
    tm.init_tree_constructor(grid,point_trajectory_set)
    mb1 = ModelBuilder(pc)
    mo1 = mb1.build_model(grid, point_trajectory_set)#生成噪声马尔可夫转移矩阵 15min
    mb1 = ModelBuilder(pc)
    mo1 = mb1.filter_model(point_trajectory_set, grid, mo1)#优化噪声马尔可夫转移矩阵
    sg1 = StateGeneration(pc)
    st_tra_list = sg1.generate_tra(mo1)

    #生成基于树的状态数据集
    syn_tra_by_tree = sg1.generate_tra_by_tree(mo1,tm)

    rlt1 = RealLocationTranslator(pc)
    real_tra_list = rlt1.translate_trajectories(grid, st_tra_list,point_trajectory_set)
    #转换基于树的真实数据集
    real_tra_list_by_tree = rlt1.translate_trajectories_by_tree(grid, syn_tra_by_tree)
    writer.save_trajectory_data_in_list_to_file(real_tra_list, fname.result_file_name)
    test = Test()
    queries = [SquareQuery(grid) for _ in range(500)]
    test.diameter_experiment(point_trajectory_set, real_tra_list_by_tree)
    test.length_experiment(point_trajectory_set, real_tra_list_by_tree,grid)
    test.density_experiment(point_trajectory_set, real_tra_list_by_tree, queries)
    # test.transition_pattern_experiment(point_trajectory_set, syn_tra_by_tree)
    print("git zhutou")
    print("bsda")

    print('end all')
    print(datetime.datetime.now())
    pass